import request from '@/utils/request'

// 用户注册
export const userRegisterService = (data) => {
    // 借助于URLSearchParam()完成参数传递
    const params = new URLSearchParams()
    for (let key in data) {
        params.append(key, data[key]);
    }
    return request.post("/user/register", params)
}

// 用户登录
export const userLoginService = (data) => {
    // 借助于URLSearchParam()完成参数传递
    // const params = new URLSearchParams()
    // const params = new FormData()
    // for (let key in data) {
    //     params.append(key, data[key]);
    // }
    return request.post("/user/login", data)
}

// 获取用户详细信息
export const userInfoService = () => {
    return request.get('/user/userInfo')
}

// 修改用户基本信息
export const updateUserInfoService = (user) => {
    return request.put('/user/update', user)
}

// 更新用户密码
export const updatePasswordService = (updateData) => {
    return request.put('/user/updatePwd', updateData);
}

// 注销用户
export const userLogoutService = () => {
    console.log("退出登录")
    return request.delete('/admin/logout')
}


// 管理员操作
// 登录
export const adminLogin = (data) => {
    return request.post("/user/login", data)
}
// 获取用户列表
export const getUserList = (data) => {
    return request.post('/admin/userlist', data)
}

// 删除某个用户
export const deleteUser = (userId) => {
    return request.delete(`/admin/deleteUser/${userId}`)
}